package view;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowEvent;

public class Student_Course extends Component implements ActionListener {
    ActionEvent event;
    public JFrame course=new JFrame();
    private JPanel panel = new JPanel(new GridLayout());
    public Student_Course(){
        init();
    }

    void init(){
        course=new JFrame();
        course.setTitle("学生选课查询");
        course.setSize(500,500);
        JRadioButton b1=new JRadioButton("大数据技术");
        JRadioButton b2=new JRadioButton("算法设计与分析");
        JRadioButton b3=new JRadioButton("Kotlin语言");
        JRadioButton b4=new JRadioButton("汇编语言");
        b1.setBounds(75,50,100,30);
        b2.setBounds(75,90,100,30);
        b3.setBounds(75,130,100,30);
        b4.setBounds(75,170,100,30);
        ButtonGroup bg=new ButtonGroup();
        JTextArea area=new JTextArea("请选择你的选课,点击选择后页面会自动退出，请注意",40,40);
        area.setEditable(false);
        area.setLineWrap(true);
        bg.add(b1);
        bg.add(b2);
        bg.add(b3);
        bg.add(b4);
        panel.add(area);
        panel.add(b1);
        panel.add(b2);
        panel.add(b3);
        panel.add(b4);

        course.add(panel);
        course.setLocationRelativeTo(null);
        course.setVisible(true);
        b1.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(b1.isSelected())
                {
                    JOptionPane.showMessageDialog(course,"你已选择大数据技术课程成功");
                    course.dispatchEvent(new WindowEvent(course,WindowEvent.WINDOW_CLOSING) );
                }
            }
        });
        b2.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(b2.isSelected())
                {
                    JOptionPane.showMessageDialog(course,"你已选择算法设计与分析课程成功");
                    course.dispatchEvent(new WindowEvent(course,WindowEvent.WINDOW_CLOSING) );
                }
            }
        });
        b3.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(b3.isSelected())
                {
                    JOptionPane.showMessageDialog(course,"你已选择Kotlin语言课程成功");
                    course.dispatchEvent(new WindowEvent(course,WindowEvent.WINDOW_CLOSING) );
                }
            }
        });
        b4.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if(b4.isSelected())
                {
                    JOptionPane.showMessageDialog(course,"你已选择汇编语言成功");
                    course.dispatchEvent(new WindowEvent(course,WindowEvent.WINDOW_CLOSING) );
                }
            }
        });

    }

    @Override
    public void actionPerformed(ActionEvent e) {

    }
}
